/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package damei;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class search extends javax.swing.JFrame {
    private Statement stmt1;
    
    

    /**
     * Creates new form search
     */
    public search() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton3 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        fname = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        fphone = new javax.swing.JTextField();
        fcarn = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        fpb = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        jButton3.setText("jButton3");

        setTitle("查询");

        jButton1.setText("查询");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("姓名");

        jLabel2.setText("手机号码");

        jLabel3.setText("车牌号码");

        jLabel4.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
        jLabel4.setText("查询条件");

        jLabel5.setText("* 使用其中一个条件查询即可");

        fpb.setText("查询");
        fpb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fpbActionPerformed(evt);
            }
        });

        jButton4.setText("查询");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE))
                    .addComponent(jLabel5)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(fcarn, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(fphone, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(fname, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1)
                            .addComponent(fpb)
                            .addComponent(jButton4))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(fname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(fphone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fpb))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(fcarn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton4)))
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        fname.setText(null);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
 usershow();
    
 try
  {
 driver ="com.mysql.jdbc.Driver";
 url    ="jdbc:mysql://192.168.1.250:3306/damei";
 user   ="root";
 password="root";
  Connection con=DriverManager.getConnection(url,user,password);
  if(!con.isClosed())
  System.out.println("打开数据库成功");
 
  
  //根据名字来查询资料
  
  stmt = con.createStatement();
  String searchnameu="select * from user where name='"+fname.getText()+"';";
   ResultSet rsuser=stmt.executeQuery(searchnameu);
    while (rsuser.next()) {
           
    //System.out.print( rsuser.getObject(3));
    Main.jno.setText(rsuser.getObject(2).toString());
    Main.jname.setText(rsuser.getObject(3).toString());
    Main.jsex.setSelectedItem(rsuser.getObject(4));
    Main.jjg.setText(rsuser.getObject(5).toString());
    Main.jphone.setText(rsuser.getObject(6).toString());
    Main.jcphone.setText(rsuser.getObject(7).toString());
    Main.qq.setText(rsuser.getObject(8).toString());
    Main.jsfz.setText(rsuser.getString(9)); 
    Main.jemail.setText(rsuser.getObject(10).toString());
    Main.jmz.setText(rsuser.getString(11));
    Main.jbd.setText(rsuser.getObject(12).toString());
    Main.jhy.setSelectedItem(rsuser.getObject(13));
    Main.jyb.setText(rsuser.getObject(14).toString());
    Main.jwb.setText(rsuser.getObject(15).toString());
    Main.jyjr.setText(rsuser.getObject(16).toString());
    Main.jyjp.setText(rsuser.getObject(17).toString());
    Main.jyjd.setText(rsuser.getObject(18).toString());
    Main.jwork.setText(rsuser.getObject(19).toString());
    Main.jaddr.setText(rsuser.getString(20));
    Main.jwaddr.setText(rsuser.getObject(21).toString());
    Main.jzx.setText(rsuser.getObject(22).toString());
    Main.jzr.setText(rsuser.getObject(23).toString());
    Main.jzsh.setText(rsuser.getObject(24).toString());
    Main.jjbr.setText(rsuser.getObject(25).toString());
    Main.jjbrq.setText(rsuser.getObject(26).toString());
    Main.jother.setText(rsuser.getObject(27).toString());
 }
 
   
  stmt1 = con.createStatement();
    String searchnamed="select * from driver where name='"+fname.getText()+"';";
     ResultSet rsdriver=stmt1.executeQuery(searchnamed);
 
    while (rsdriver.next()) {
        Main.brand.setText(rsdriver.getObject(5).toString());
        Main.cartype.setText(rsdriver.getObject(6).toString());
        Main.jszh.setText(rsdriver.getObject(7).toString());
        Main.gcrq.setText(rsdriver.getObject(8).toString());
        Main.lzrq.setText(rsdriver.getObject(9).toString());
        Main.pl.setText(rsdriver.getObject(10).toString());
        Main.dw.setSelectedItem(rsdriver.getObject(11));
        Main.cphm.setText(rsdriver.getObject(12).toString());
        Main.jl.setText(rsdriver.getObject(13).toString());
        Main.xsz.setText(rsdriver.getObject(14).toString());
        Main.tbgs.setText(rsdriver.getString(15));
        Main.tbrq.setText(rsdriver.getString(16));
        
   
 }
    System.out.println("查询成功");
  
  stmt.close();
  stmt1.close();
  con.close();
  }
   catch(Exception e){
            System.out.print("Error occurred in inserting data");
            e.printStackTrace();
        }
//  
//   //     JOptionPane.showMessageDialog(this,"请使用一个条件查询");
//

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        usershow() ;
        try
  {
 driver ="com.mysql.jdbc.Driver";
 url    ="jdbc:mysql://192.168.1.250:3306/damei";
 user   ="root";
 password="root";
  Connection con=DriverManager.getConnection(url,user,password);
  if(!con.isClosed())
  System.out.println("打开数据库成功");

 
  
 //根据车牌号码来查询
  
  stmt = con.createStatement();
  String searchcar="select * from user where cphm='"+fcarn.getText()+"';";
   ResultSet rsuser=stmt.executeQuery(searchcar);
    while (rsuser.next()) {
           
    //System.out.print( rsuser.getObject(3));
    Main.jno.setText(rsuser.getObject(2).toString());
    Main.jname.setText(rsuser.getObject(3).toString());
    Main.jsex.setSelectedItem(rsuser.getObject(4));
    Main.jjg.setText(rsuser.getObject(5).toString());
    Main.jphone.setText(rsuser.getObject(6).toString());
    Main.jcphone.setText(rsuser.getObject(7).toString());
    Main.qq.setText(rsuser.getObject(8).toString());
    Main.jsfz.setText(rsuser.getString(9)); 
    Main.jemail.setText(rsuser.getObject(10).toString());
    Main.jmz.setText(rsuser.getString(11));
    Main.jbd.setText(rsuser.getObject(12).toString());
    Main.jhy.setSelectedItem(rsuser.getObject(13));
    Main.jyb.setText(rsuser.getObject(14).toString());
    Main.jwb.setText(rsuser.getObject(15).toString());
    Main.jyjr.setText(rsuser.getObject(16).toString());
    Main.jyjp.setText(rsuser.getObject(17).toString());
    Main.jyjd.setText(rsuser.getObject(18).toString());
    Main.jwork.setText(rsuser.getObject(19).toString());
    Main.jaddr.setText(rsuser.getString(20));
    Main.jwaddr.setText(rsuser.getObject(21).toString());
    Main.jzx.setText(rsuser.getObject(22).toString());
    Main.jzr.setText(rsuser.getObject(23).toString());
    Main.jzsh.setText(rsuser.getObject(24).toString());
    Main.jjbr.setText(rsuser.getObject(25).toString());
    Main.jjbrq.setText(rsuser.getObject(26).toString());
    Main.jother.setText(rsuser.getObject(27).toString());
 }
 
   
  stmt1 = con.createStatement();
    String searchcarn="select * from driver where cphm='"+fcarn.getText()+"';";
     ResultSet rsdriver=stmt1.executeQuery(searchcarn);
 
    while (rsdriver.next()) {
        Main.brand.setText(rsdriver.getObject(5).toString());
        Main.cartype.setText(rsdriver.getObject(6).toString());
        Main.jszh.setText(rsdriver.getObject(7).toString());
        Main.gcrq.setText(rsdriver.getObject(8).toString());
        Main.lzrq.setText(rsdriver.getObject(9).toString());
        Main.pl.setText(rsdriver.getObject(10).toString());
        Main.dw.setSelectedItem(rsdriver.getObject(11));
        Main.cphm.setText(rsdriver.getObject(12).toString());
        Main.jl.setText(rsdriver.getObject(13).toString());
        Main.xsz.setText(rsdriver.getObject(14).toString());
        Main.tbgs.setText(rsdriver.getString(15));
        Main.tbrq.setText(rsdriver.getString(16));
   
 }
    System.out.println("查询成功");
  
  stmt.close();
  stmt1.close();
  con.close();
  }
   catch(Exception e){
            System.out.print("Error occurred in inserting data");
            e.printStackTrace();
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void fpbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fpbActionPerformed
        // TODO add your handling code here:
        usershow() ;
           try
  {
 driver ="com.mysql.jdbc.Driver";
 url    ="jdbc:mysql://192.168.1.250:3306/damei";
 user   ="root";
 password="root";
  Connection con=DriverManager.getConnection(url,user,password);
  if(!con.isClosed())
  System.out.println("打开数据库成功");

  
  
 //根据手机号码来查询
  
  stmt = con.createStatement();
  String searchcar="select * from user where cphone='"+fphone.getText()+"';";
   ResultSet rsuser=stmt.executeQuery(searchcar);
    while (rsuser.next()) {
           
    //System.out.print( rsuser.getObject(3));
    Main.jno.setText(rsuser.getObject(2).toString());
    Main.jname.setText(rsuser.getObject(3).toString());
    Main.jsex.setSelectedItem(rsuser.getObject(4));
    Main.jjg.setText(rsuser.getObject(5).toString());
    Main.jphone.setText(rsuser.getObject(6).toString());
    Main.jcphone.setText(rsuser.getObject(7).toString());
    Main.qq.setText(rsuser.getObject(8).toString());
    Main.jsfz.setText(rsuser.getString(9)); 
    Main.jemail.setText(rsuser.getObject(10).toString());
    Main.jmz.setText(rsuser.getString(11));
    Main.jbd.setText(rsuser.getObject(12).toString());
    Main.jhy.setSelectedItem(rsuser.getObject(13));
    Main.jyb.setText(rsuser.getObject(14).toString());
    Main.jwb.setText(rsuser.getObject(15).toString());
    Main.jyjr.setText(rsuser.getObject(16).toString());
    Main.jyjp.setText(rsuser.getObject(17).toString());
    Main.jyjd.setText(rsuser.getObject(18).toString());
    Main.jwork.setText(rsuser.getObject(19).toString());
    Main.jaddr.setText(rsuser.getString(20));
    Main.jwaddr.setText(rsuser.getObject(21).toString());
    Main.jzx.setText(rsuser.getObject(22).toString());
    Main.jzr.setText(rsuser.getObject(23).toString());
    Main.jzsh.setText(rsuser.getObject(24).toString());
    Main.jjbr.setText(rsuser.getObject(25).toString());
    Main.jjbrq.setText(rsuser.getObject(26).toString());
    Main.jother.setText(rsuser.getObject(27).toString());
 }
 
   
  stmt1 = con.createStatement();
    String searchcarn="select * from driver where cphone='"+fphone.getText()+"';";
     ResultSet rsdriver=stmt1.executeQuery(searchcarn);
 
    while (rsdriver.next()) {
        Main.brand.setText(rsdriver.getObject(5).toString());
        Main.cartype.setText(rsdriver.getObject(6).toString());
        Main.jszh.setText(rsdriver.getObject(7).toString());
        Main.gcrq.setText(rsdriver.getObject(8).toString());
        Main.lzrq.setText(rsdriver.getObject(9).toString());
        Main.pl.setText(rsdriver.getObject(10).toString());
        Main.dw.setSelectedItem(rsdriver.getObject(11));
        Main.cphm.setText(rsdriver.getObject(12).toString());
        Main.jl.setText(rsdriver.getObject(13).toString());
        Main.xsz.setText(rsdriver.getObject(14).toString());
        Main.tbgs.setText(rsdriver.getString(15));
        Main.tbrq.setText(rsdriver.getString(16));
   
 }
    System.out.println("查询成功");
  
  stmt.close();
  stmt1.close();
  con.close();
  }
   catch(Exception e){
            System.out.print("Error occurred in inserting data");
            e.printStackTrace();
        }
    }//GEN-LAST:event_fpbActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(search.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(search.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(search.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(search.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new search().setVisible(true);
            }
        });
    }
    
    private static String url;
    private static String driver;
    private static String user;
    private static String password;
    private Statement stmt;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private static javax.swing.JTextField fcarn;
    private static javax.swing.JTextField fname;
    private javax.swing.JButton fpb;
    private static javax.swing.JTextField fphone;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables

    private void usershow() {
     Main.users.setVisible(true);
     Main.jf.setVisible(false);
     Main.yw.setVisible(false); 
     Main. other.setVisible(false);
     Main. main.setVisible(false);
     Main.editbutton.enableInputMethods(true);
    }
}



